﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SpaceMan.Particles
{
    class MAN_ParticleManager
    {
        List<I_Particle> ParticleList;
        List<I_Particle> ParticlesToBeAdded;
        public MAN_ParticleManager()
        {
            ParticleList = new List<I_Particle>();
            ParticlesToBeAdded = new List<I_Particle>();
        }

        public void Update()
        {
            foreach (I_Particle particle in ParticlesToBeAdded)
            {
                ParticleList.Add(particle);
            }
            ParticlesToBeAdded.Clear();

            foreach (I_Particle particle in ParticleList)
            {
                particle.Update();
            }

            for (int i = ParticleList.Count - 1; i >= 0; i--)
            {
                if (ParticleList[i].MarkedForDeletion)
                {
                    ParticleList.RemoveAt(i);
                }
            }
        }

        public void Draw(SpriteBatch spriteBatch, DrawMode drawMode, Rectangle drawSpace)
        {
            foreach (I_Particle particle in ParticleList)
            {
                particle.Draw(spriteBatch, drawMode, drawSpace);
            }
        }

        public void GiveParticle(I_Particle Particle)
        {
            ParticlesToBeAdded.Add(Particle);
        }
    }
}
